<?php 
	namespace Home\Model;
	use Think\Model;
	class GoodsModel extends Model{
		public function getAll()
		{
			$list=$this->field('
					 g.id        gid,
					 g.name      gname,
					 g.is_new    gnew,
					 g.is_hot    ghot,
					 g.is_bast   gbast,
					 g.price     gp,
					 g.stock     gs,
					 gi.name     giname,
					 c.name      cname,
					 g.addtime   gtime')
					->table('goods     g,
							goods_img   gi,
							category    c')
					->where('
						g.id=gi.goods_id
						and
							g.cate_id=c.id
						and
							gi.is_cover=1
						and
							g.is_bast=1')
					->select();
				return $list;
				//var_dump($list);exit;
		}

		public function getSingle($id)
		{
			$list=$this->field('
					 g.id        gid,
					 g.name      gname,
					 g.is_new    gnew,
					 g.is_hot    ghot,
					 g.is_bast   gbast,
					 g.price     gp,
					 g.stock     gs,
					 g.description gd,
					 gi.name     giname,
					 c.name      cname,
					 g.addtime   gtime')
					->table('goods     g,
							goods_img   gi,
							category    c')
					->where('
						g.id=gi.goods_id
						and
							g.cate_id=c.id
						and
							gi.is_cover=1
						and
							g.id='.$id)
					->select();
				return $list;
		}
	}
?>